﻿@using System.Text;
@{
    var fact = ViewBag.Factory as IEntityOperate;
    var fi = fact.Fields.FirstOrDefault(e => e.Name.EqualIgnoreCase("Deleted", "IsDelete", "IsDeleted"));
    var entity = Model as IEntity;

    var rv = entity.GetRouteKey();

    var user = ViewBag.User as IUser ?? User.Identity as IUser;

    var ajax = true;
    if (ViewBag.AjaxDelete is Boolean)
    {
        ajax = (Boolean)ViewBag.AjaxDelete;
    }
}
@if (user.Has(PermissionFlags.Update))
{
    <i class="glyphicon glyphicon-edit" style="color: blue;"></i>
    <a href="@Url.Action("Edit", rv)" class="editcell">编辑</a>
}
else if (user.Has(PermissionFlags.Detail))
{
    <i class="glyphicon glyphicon-edit" style="color: blue;"></i>
    <a href="@Url.Action("Detail", rv)" class="editcell">查看</a>
}
@if (user.Has(PermissionFlags.Delete))
{
    if (fi != null && fi.Type == typeof(Boolean) && (Boolean)entity[fi.Name])
    {
        <i class="glyphicon glyphicon-transfer" style="color: green;"></i>
        if (ajax)
        {
            <a href="@Url.Action("DeleteAjax", rv)" data-action="delete" data-ajax="1" onclick="return confirm('确认恢复？');">恢复</a>
        }
        else
        {
            <a href="@Url.Action("Delete", rv)" onclick="return confirm('确认恢复？');">恢复</a>
        }
    }
    else
    {
        <i class="glyphicon glyphicon-remove" style="color: red;"></i>
        if (ajax)
        {
            <a href="@Url.Action("DeleteAjax", rv)" data-action="delete" data-ajax="1" onclick="return confirm('确认删除？');">删除</a>
        }
        else
        {
            <a href="@Url.Action("Delete", rv)" onclick="return confirm('确认删除？');">删除</a>
        }
    }
}